package org.dizem.groupon.model.domain;

import org.dizem.groupon.Constants;

import javax.persistence.*;
import java.util.Date;

/**
 * UserEntity: dizem@126.com
 * Time: 11-6-20 下午8:42
 */

@Entity(name = "t_user")
public class UserEntity {
	private int id;
	private String username;
	private String password;
	private String passwordConfirm;
	private CityEntity city;
	private String mobile;
	private String email;
	private String address;
	private String zipCode;
	private Date registerTime;
	private int accountType;
	private String realname;
	private String authCode;
	private String lastLoginIP;
	private Date lastLoginTIme;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(length = 16,
			nullable = false,
			unique = true)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(length = 32,
			nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@ManyToOne(targetEntity = CityEntity.class)
	public CityEntity getCity() {
		return city;
	}

	public void setCity(CityEntity city) {
		this.city = city;
	}

	@Column(length = 11)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(length = 30, nullable = false)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(nullable = false)
	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	@Column(nullable = false)
	public int getAccountType() {
		return accountType;
	}

	public void setAccountType(int accountType) {
		this.accountType = accountType;
	}


	@Column(length = 100)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(length = 10)
	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	@Column(length = 20)
	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	@Transient
	public String getPasswordConfirm() {
		return passwordConfirm;
	}

	public void setPasswordConfirm(String passwordConfirm) {
		this.passwordConfirm = passwordConfirm;
	}

	@Column(length = 50)
	public String getAuthCode() {
		return authCode;
	}

	public void setAuthCode(String authCode) {
		this.authCode = authCode;
	}


	@Column(length = 50)
	public String getLastLoginIP() {
		return lastLoginIP;
	}

	public void setLastLoginIP(String lastLoginIP) {
		this.lastLoginIP = lastLoginIP;
	}

	public Date getLastLoginTIme() {
		return lastLoginTIme;
	}

	public void setLastLoginTIme(Date lastLoginTIme) {
		this.lastLoginTIme = lastLoginTIme;
	}

	@Override
	public String toString() {
		return "UserEntity{" +
				"id=" + id +
				", username='" + username + '\'' +
				", password='" + password + '\'' +
				", passwordConfirm='" + passwordConfirm + '\'' +
				", city=" + city +
				", mobile='" + mobile + '\'' +
				", email='" + email + '\'' +
				", registerTime=" + registerTime +
				'}';
	}

	@Transient
	public String getFormatRegTime() {
		return Constants.DATE_FORMAT.format(registerTime);
	}
}
